Being able to use a text editor is probably one of the most critical skills to have as a system administrator. You constantly need to edit con fig files, write scripts or make changes to system files …….. all of which require you to use a text editor.
Vi(or) Vim: Text editor with great flexibility. Emacs : similar to vi, an advanced text editor with many features. Nano : A basic text editor for quick editing
Syn: Vim [arguments] [file] Arguments: - R -----> opens a file in read –only mode - o -----> Open two files at a time + -----> Starts at the end of the file + <rum> -----> Start at line <num> Insert mode options: i --------> To begin insert mode at the current cursor position. I -------->To Insert at the beginning of the current line a-------->To append to the next word’s letter. A --------> To append at the end of the line o -------->To insert a new line below the cursor position. O --------> To Insert a new line above the cursor position. Commands for command mode: e --------> Moves to the end of a word b --------> Moves to the beginning of a word. $ -------->Moves to the end of a line. ˄ -------->Moves to the beginning of a line H -------->Moves to the first line onscreen M --------> Moves to the middle line onscreen L -------->Moves to the last line onscreen x (nx) -------->Deletes current character. dd (ndd)-------->Deletes the current line dw (ndw)-------->Deletes current word. Yy(nyy) --------> yanks (copies) the current line p -------->paste below the cursor line P -------->paste above the cursor line U-------->undo the last action. gg(ngg)-------->go to beginning of the file G -------->End of the file. W (n)-------->To move the cursor forward, word by word. b(n) --------> To move the cursor back word, word by word Ctrl +f -------->To forward one page. Ctrl +b -------->To back word one page. / -------->To search a word in the file. n -------->Find next occurrence of search word. N --------> find previous occurrence of search word. . --------> Repeat last command action. Commands for last line mode: :q -------->To quit without saving :w -------->To save the changes :wq -------->To save & quit :wq! (or) :x --------> To save & quit with forcefully. :set nu (or) :se nu -------> To setting line numbers. :set nonu (or) :se nonu------> To remove line numbers. :n ------>Jumps to line n :$d ------>To delete last line :! <unixcmd> ------> To execute unix cmds :x ------>To give password to the file and remove password. :/storing / ------>search a word in the file.
Desired to gain proficiency on Linux ? Explore the blog post on Linux training online to become a pro in Linux.
: % S/root/dog/ To replace storing “dog” for the first instance : %s/root/dog/g For each instance of a line. : %s/root/dog/gi To ignore case sensitive : %s/root/dog/gc ask for confirmation
Any unix command can be Executed from the vi command line by typing an “!” before the unix command. EX: : ! Pwd : r ! data Reads the results from the date command into a new line following the cursor : r ! cat file1
: 1,4 CO 10
: 3,7 mo 8
: 1,30 w test1
: 8,20 w >> test1
: r/etc/passwd Managing two files at time: $vim -0 file1 file2 (or) $vim file1 file2 Options: :n ----> edit next file (file2) :rew ----> Rewind to the file (file1) (or)
Press two times
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.